import { StateCreator } from 'zustand';

export interface Lint {
  lineNo: string;
  file: string;
  fromCol?: string;
  toCol?: string;
  severity: 'info' | 'warning' | 'error';
  msg: string;
}

export interface OutlineDetail {
  Name: string;
  Line: number;
  Ch: number;
}
export interface OutlineResponse {
  constDecls?: OutlineDetail[];
  funcDecls?: OutlineDetail[];
  imports?: OutlineDetail[];
  interfaceDecls?: OutlineDetail[];
  package?: OutlineDetail[];
  structDecls?: OutlineDetail[];
  typeDecls?: OutlineDetail[];
  varDecls?: OutlineDetail[];
}

interface LintData {
  fileLints: {
    [key: string]: Lint[]
  };
  fileDecls: {
    [key: string]: OutlineResponse
  }
}

const initDate = {
  fileLints: {},
  fileDecls: {}
};

export type LintStore = LintData & {
  setFileLints: (item: LintData['fileLints']) => void;
  setFileDecls: (item: LintData['fileDecls']) => void;
  updateFileDecls: (item: LintData['fileDecls']) => void;
};

export const lintStore: StateCreator<LintStore> = (set) => ({
  ...initDate,
  setFileLints: (item) => set(() => ({
    fileLints: item
  })),
  setFileDecls: (item) => set(() => ({
    fileDecls: item
  })),
  updateFileDecls: (item) => set((stat) => ({
    fileDecls: {
      ...stat.fileDecls,
      ...item
    }
  }))
});
